package com.testfileupload.uploadimg.design.single.chan;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Emperor {
    //皇帝的数量
    private static int maxNumOfEmperor = 2;
    //皇帝的名称
    private static List<String> nameList = new ArrayList<>();
    //皇帝
    private static List<Emperor> emperors = new ArrayList<>();
    //当前皇帝序列号
    private static int currentId = 0;

    private Emperor() {

    }

    private Emperor(String name) {
        nameList.add(name);
    }

    static {
        for (int i = 1; i <= maxNumOfEmperor; i++) {
            emperors.add(new Emperor("皇帝" + i));
        }
    }

    public static Emperor getInstence() {
        Random random = new Random();
        currentId = random.nextInt(maxNumOfEmperor);
        return emperors.get(currentId);
    }

    public void say() {
        System.out.println(nameList.get(currentId));
    }
}
